home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / fileutil / fileutils-3.16.tar.gz / fileutils-3.16.tar / fileutils-3.16 / lib / getdate.c < prev    next >
C/C++ Source or Header  |  1997-01-18  |  52KB  |  2,007 lines

  1.  
  2. /*  A Bison parser, made from getdate.y
  3.  by  GNU Bison version 1.25
  4.   */
  5.  
  6. #define YYBISON 1  /* Identify Bison output.  */
  7.  
  8. #define    tAGO    258
  9. #define    tDAY    259
  10. #define    tDAY_UNIT    260
  11. #define    tDAYZONE    261
  12. #define    tDST    262
  13. #define    tHOUR_UNIT    263
  14. #define    tID    264
  15. #define    tMERIDIAN    265
  16. #define    tMINUTE_UNIT    266
  17. #define    tMONTH    267
  18. #define    tMONTH_UNIT    268
  19. #define    tSEC_UNIT    269
  20. #define    tSNUMBER    270
  21. #define    tUNUMBER    271
  22. #define    tYEAR_UNIT    272
  23. #define    tZONE    273
  24.  
  25. #line 1 "getdate.y"
  26.  
  27. /*
  28. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  29. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  30. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  31. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  32. **
  33. **  This grammar has 13 shift/reduce conflicts.
  34. **
  35. **  This code is in the public domain and has no copyright.
  36. */
  37.  
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. # ifdef FORCE_ALLOCA_H
  41. #  include <alloca.h>
  42. # endif
  43. #endif
  44.  
  45. /* Since the code of getdate.y is not included in the Emacs executable
  46.    itself, there is no need to #define static in this file.  Even if
  47.    the code were included in the Emacs executable, it probably
  48.    wouldn't do any harm to #undef it here; this will only cause
  49.    problems if we try to write to a static variable, which I don't
  50.    think this code needs to do.  */
  51. #ifdef emacs
  52. # undef static
  53. #endif
  54.  
  55. #include <stdio.h>
  56. #include <ctype.h>
  57.  
  58. #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
  59. # define IN_CTYPE_DOMAIN(c) 1
  60. #else
  61. # define IN_CTYPE_DOMAIN(c) isascii(c)
  62. #endif
  63.  
  64. #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
  65. #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
  66. #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
  67. #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
  68.  
  69. /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
  70.    - Its arg may be any int or unsigned int; it need not be an unsigned char.
  71.    - It's guaranteed to evaluate its argument exactly once.
  72.    - It's typically faster.
  73.    Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
  74.    only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
  75.    it's important to use the locale's definition of `digit' even when the
  76.    host does not conform to Posix.  */
  77. #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
  78.  
  79. #include "getdate.h"
  80.  
  81. #if defined (STDC_HEADERS) || defined (USG)
  82. # include <string.h>
  83. #endif
  84.  
  85. /* Some old versions of bison generate parsers that use bcopy.
  86.    That loses on systems that don't provide the function, so we have
  87.    to redefine it here.  */
  88. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  89. # define bcopy(from, to, len) memcpy ((to), (from), (len))
  90. #endif
  91.  
  92. extern struct tm    *gmtime ();
  93. extern struct tm    *localtime ();
  94. extern time_t        mktime ();
  95.  
  96. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  97.    as well as gratuitiously global symbol names, so we can have multiple
  98.    yacc generated parsers in the same program.  Note that these are only
  99.    the variables produced by yacc.  If other parser generators (bison,
  100.    byacc, etc) produce additional global names that conflict at link time,
  101.    then those parser generators need to be fixed instead of adding those
  102.    names to this list. */
  103.  
  104. #define yymaxdepth gd_maxdepth
  105. #define yyparse gd_parse
  106. #define yylex   gd_lex
  107. #define yyerror gd_error
  108. #define yylval  gd_lval
  109. #define yychar  gd_char
  110. #define yydebug gd_debug
  111. #define yypact  gd_pact
  112. #define yyr1    gd_r1
  113. #define yyr2    gd_r2
  114. #define yydef   gd_def
  115. #define yychk   gd_chk
  116. #define yypgo   gd_pgo
  117. #define yyact   gd_act
  118. #define yyexca  gd_exca
  119. #define yyerrflag gd_errflag
  120. #define yynerrs gd_nerrs
  121. #define yyps    gd_ps
  122. #define yypv    gd_pv
  123. #define yys     gd_s
  124. #define yy_yys  gd_yys
  125. #define yystate gd_state
  126. #define yytmp   gd_tmp
  127. #define yyv     gd_v
  128. #define yy_yyv  gd_yyv
  129. #define yyval   gd_val
  130. #define yylloc  gd_lloc
  131. #define yyreds  gd_reds          /* With YYDEBUG defined */
  132. #define yytoks  gd_toks          /* With YYDEBUG defined */
  133. #define yylhs   gd_yylhs
  134. #define yylen   gd_yylen
  135. #define yydefred gd_yydefred
  136. #define yydgoto gd_yydgoto
  137. #define yysindex gd_yysindex
  138. #define yyrindex gd_yyrindex
  139. #define yygindex gd_yygindex
  140. #define yytable  gd_yytable
  141. #define yycheck  gd_yycheck
  142.  
  143. static int yylex ();
  144. static int yyerror ();
  145.  
  146. #define EPOCH        1970
  147. #define HOUR(x)        ((x) * 60)
  148.  
  149. #define MAX_BUFF_LEN    128   /* size of buffer to read the date into */
  150.  
  151. /*
  152. **  An entry in the lexical lookup table.
  153. */
  154. typedef struct _TABLE {
  155.     const char    *name;
  156.     int        type;
  157.     int        value;
  158. } TABLE;
  159.  
  160.  
  161. /*
  162. **  Meridian:  am, pm, or 24-hour style.
  163. */
  164. typedef enum _MERIDIAN {
  165.     MERam, MERpm, MER24
  166. } MERIDIAN;
  167.  
  168.  
  169. /*
  170. **  Global variables.  We could get rid of most of these by using a good
  171. **  union as the yacc stack.  (This routine was originally written before
  172. **  yacc had the %union construct.)  Maybe someday; right now we only use
  173. **  the %union very rarely.
  174. */
  175. static const char    *yyInput;
  176. static int    yyDayOrdinal;
  177. static int    yyDayNumber;
  178. static int    yyHaveDate;
  179. static int    yyHaveDay;
  180. static int    yyHaveRel;
  181. static int    yyHaveTime;
  182. static int    yyHaveZone;
  183. static int    yyTimezone;
  184. static int    yyDay;
  185. static int    yyHour;
  186. static int    yyMinutes;
  187. static int    yyMonth;
  188. static int    yySeconds;
  189. static int    yyYear;
  190. static MERIDIAN    yyMeridian;
  191. static int    yyRelDay;
  192. static int    yyRelHour;
  193. static int    yyRelMinutes;
  194. static int    yyRelMonth;
  195. static int    yyRelSeconds;
  196. static int    yyRelYear;
  197.  
  198.  
  199. #line 175 "getdate.y"
  200. typedef union {
  201.     int            Number;
  202.     enum _MERIDIAN    Meridian;
  203. } YYSTYPE;
  204. #include <stdio.h>
  205.  
  206. #ifndef __cplusplus
  207. #ifndef __STDC__
  208. #define const
  209. #endif
  210. #endif
  211.  
  212.  
  213.  
  214. #define    YYFINAL        61
  215. #define    YYFLAG        -32768
  216. #define    YYNTBASE    22
  217.  
  218. #define YYTRANSLATE(x) ((unsigned)(x) <= 273 ? yytranslate[x] : 32)
  219.  
  220. static const char yytranslate[] = {     0,
  221.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  225.      2,     2,     2,    20,     2,     2,    21,     2,     2,     2,
  226.      2,     2,     2,     2,     2,     2,     2,    19,     2,     2,
  227.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  228.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  229.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  230.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  231.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  232.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  233.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  234.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  235.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  236.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  237.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  238.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  239.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  240.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  241.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  242.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  243.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  244.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  245.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  246.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  247.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  248.     16,    17,    18
  249. };
  250.  
  251. #if YYDEBUG != 0
  252. static const short yyprhs[] = {     0,
  253.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  254.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  255.     62,    68,    72,    76,    79,    84,    87,    91,    94,    96,
  256.     99,   102,   104,   107,   110,   112,   115,   118,   120,   123,
  257.    126,   128,   131,   134,   136,   139,   142,   144,   146,   147
  258. };
  259.  
  260. static const short yyrhs[] = {    -1,
  261.     22,    23,     0,    24,     0,    25,     0,    27,     0,    26,
  262.      0,    28,     0,    30,     0,    16,    10,     0,    16,    19,
  263.     16,    31,     0,    16,    19,    16,    15,     0,    16,    19,
  264.     16,    19,    16,    31,     0,    16,    19,    16,    19,    16,
  265.     15,     0,    18,     0,     6,     0,    18,     7,     0,     4,
  266.      0,     4,    20,     0,    16,     4,     0,    16,    21,    16,
  267.      0,    16,    21,    16,    21,    16,     0,    16,    15,    15,
  268.      0,    16,    12,    15,     0,    12,    16,     0,    12,    16,
  269.     20,    16,     0,    16,    12,     0,    16,    12,    16,     0,
  270.     29,     3,     0,    29,     0,    16,    17,     0,    15,    17,
  271.      0,    17,     0,    16,    13,     0,    15,    13,     0,    13,
  272.      0,    16,     5,     0,    15,     5,     0,     5,     0,    16,
  273.      8,     0,    15,     8,     0,     8,     0,    16,    11,     0,
  274.     15,    11,     0,    11,     0,    16,    14,     0,    15,    14,
  275.      0,    14,     0,    16,     0,     0,    10,     0
  276. };
  277.  
  278. #endif
  279.  
  280. #if YYDEBUG != 0
  281. static const short yyrline[] = { 0,
  282.    191,   192,   195,   198,   201,   204,   207,   210,   213,   219,
  283.    225,   234,   240,   252,   255,   258,   264,   268,   272,   278,
  284.    282,   300,   306,   312,   316,   321,   325,   332,   340,   343,
  285.    346,   349,   352,   355,   358,   361,   364,   367,   370,   373,
  286.    376,   379,   382,   385,   388,   391,   394,   399,   432,   436
  287. };
  288. #endif
  289.  
  290.  
  291. #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
  292.  
  293. static const char * const yytname[] = {   "$","error","$undefined.","tAGO","tDAY",
  294. "tDAY_UNIT","tDAYZONE","tDST","tHOUR_UNIT","tID","tMERIDIAN","tMINUTE_UNIT",
  295. "tMONTH","tMONTH_UNIT","tSEC_UNIT","tSNUMBER","tUNUMBER","tYEAR_UNIT","tZONE",
  296. "':'","','","'/'","spec","item","time","zone","day","date","rel","relunit","number",
  297. "o_merid", NULL
  298. };
  299. #endif
  300.  
  301. static const short yyr1[] = {     0,
  302.     22,    22,    23,    23,    23,    23,    23,    23,    24,    24,
  303.     24,    24,    24,    25,    25,    25,    26,    26,    26,    27,
  304.     27,    27,    27,    27,    27,    27,    27,    28,    28,    29,
  305.     29,    29,    29,    29,    29,    29,    29,    29,    29,    29,
  306.     29,    29,    29,    29,    29,    29,    29,    30,    31,    31
  307. };
  308.  
  309. static const short yyr2[] = {     0,
  310.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  311.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  312.      5,     3,     3,     2,     4,     2,     3,     2,     1,     2,
  313.      2,     1,     2,     2,     1,     2,     2,     1,     2,     2,
  314.      1,     2,     2,     1,     2,     2,     1,     1,     0,     1
  315. };
  316.  
  317. static const short yydefact[] = {     1,
  318.      0,    17,    38,    15,    41,    44,     0,    35,    47,     0,
  319.     48,    32,    14,     2,     3,     4,     6,     5,     7,    29,
  320.      8,    18,    24,    37,    40,    43,    34,    46,    31,    19,
  321.     36,    39,     9,    42,    26,    33,    45,     0,    30,     0,
  322.      0,    16,    28,     0,    23,    27,    22,    49,    20,    25,
  323.     50,    11,     0,    10,     0,    49,    21,    13,    12,     0,
  324.      0
  325. };
  326.  
  327. static const short yydefgoto[] = {     1,
  328.     14,    15,    16,    17,    18,    19,    20,    21,    54
  329. };
  330.  
  331. static const short yypact[] = {-32768,
  332.      0,   -19,-32768,-32768,-32768,-32768,   -13,-32768,-32768,    30,
  333.     15,-32768,    14,-32768,-32768,-32768,-32768,-32768,-32768,    19,
  334. -32768,-32768,     4,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  335. -32768,-32768,-32768,-32768,    -6,-32768,-32768,    16,-32768,    17,
  336.     23,-32768,-32768,    24,-32768,-32768,-32768,    27,    28,-32768,
  337. -32768,-32768,    29,-32768,    32,    -8,-32768,-32768,-32768,    50,
  338. -32768
  339. };
  340.  
  341. static const short yypgoto[] = {-32768,
  342. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  343. };
  344.  
  345.  
  346. #define    YYLAST        51
  347.  
  348.  
  349. static const short yytable[] = {    60,
  350.     22,    51,    23,     2,     3,     4,    58,     5,    45,    46,
  351.      6,     7,     8,     9,    10,    11,    12,    13,    30,    31,
  352.     42,    43,    32,    44,    33,    34,    35,    36,    37,    38,
  353.     47,    39,    48,    40,    24,    41,    51,    25,    49,    50,
  354.     26,    52,    27,    28,    56,    53,    29,    57,    55,    61,
  355.     59
  356. };
  357.  
  358. static const short yycheck[] = {     0,
  359.     20,    10,    16,     4,     5,     6,    15,     8,    15,    16,
  360.     11,    12,    13,    14,    15,    16,    17,    18,     4,     5,
  361.      7,     3,     8,    20,    10,    11,    12,    13,    14,    15,
  362.     15,    17,    16,    19,     5,    21,    10,     8,    16,    16,
  363.     11,    15,    13,    14,    16,    19,    17,    16,    21,     0,
  364.     56
  365. };
  366. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  367. #line 3 "/p/share/bison.simple"
  368.  
  369. /* Skeleton output parser for bison,
  370.    Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
  371.  
  372.    This program is free software; you can redistribute it and/or modify
  373.    it under the terms of the GNU General Public License as published by
  374.    the Free Software Foundation; either version 2, or (at your option)
  375.    any later version.
  376.  
  377.    This program is distributed in the hope that it will be useful,
  378.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  379.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  380.    GNU General Public License for more details.
  381.  
  382.    You should have received a copy of the GNU General Public License
  383.    along with this program; if not, write to the Free Software
  384.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  385.  
  386. /* As a special exception, when this file is copied by Bison into a
  387.    Bison output file, you may use that output file without restriction.
  388.    This special exception was added by the Free Software Foundation
  389.    in version 1.24 of Bison.  */
  390.  
  391. #ifndef alloca
  392. #ifdef __GNUC__
  393. #define alloca __builtin_alloca
  394. #else /* not GNU C.  */
  395. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || defined (HAVE_ALLOCA_H)
  396. #include <alloca.h>
  397. #else /* not sparc */
  398. #if defined (MSDOS) && !defined (__TURBOC__)
  399. #include <malloc.h>
  400. #else /* not MSDOS, or __TURBOC__ */
  401. #if defined(_AIX)
  402. #include <malloc.h>
  403.  #pragma alloca
  404. #else /* not MSDOS, __TURBOC__, or _AIX */
  405. #ifdef __hpux
  406. #ifdef __cplusplus
  407. extern "C" {
  408. void *alloca (unsigned int);
  409. };
  410. #else /* not __cplusplus */
  411. void *alloca ();
  412. #endif /* not __cplusplus */
  413. #endif /* __hpux */
  414. #endif /* not _AIX */
  415. #endif /* not MSDOS, or __TURBOC__ */
  416. #endif /* not sparc.  */
  417. #endif /* not GNU C.  */
  418. #endif /* alloca not defined.  */
  419.  
  420. /* This is the parser code that is written into each bison parser
  421.   when the %semantic_parser declaration is not specified in the grammar.
  422.   It was written by Richard Stallman by simplifying the hairy parser
  423.   used when %semantic_parser is specified.  */
  424.  
  425. /* Note: there must be only one dollar sign in this file.
  426.    It is replaced by the list of actions, each action
  427.    as one case of the switch.  */
  428.  
  429. #define yyerrok        (yyerrstatus = 0)
  430. #define yyclearin    (yychar = YYEMPTY)
  431. #define YYEMPTY        -2
  432. #define YYEOF        0
  433. #define YYACCEPT    return(0)
  434. #define YYABORT     return(1)
  435. #define YYERROR        goto yyerrlab1
  436. /* Like YYERROR except do call yyerror.
  437.    This remains here temporarily to ease the
  438.    transition to the new meaning of YYERROR, for GCC.
  439.    Once GCC version 2 has supplanted version 1, this can go.  */
  440. #define YYFAIL        goto yyerrlab
  441. #define YYRECOVERING()  (!!yyerrstatus)
  442. #define YYBACKUP(token, value) \
  443. do                                \
  444.   if (yychar == YYEMPTY && yylen == 1)                \
  445.     { yychar = (token), yylval = (value);            \
  446.       yychar1 = YYTRANSLATE (yychar);                \
  447.       YYPOPSTACK;                        \
  448.       goto yybackup;                        \
  449.     }                                \
  450.   else                                \
  451.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  452. while (0)
  453.  
  454. #define YYTERROR    1
  455. #define YYERRCODE    256
  456.  
  457. #ifndef YYPURE
  458. #define YYLEX        yylex()
  459. #endif
  460.  
  461. #ifdef YYPURE
  462. #ifdef YYLSP_NEEDED
  463. #ifdef YYLEX_PARAM
  464. #define YYLEX        yylex(&yylval, &yylloc, YYLEX_PARAM)
  465. #else
  466. #define YYLEX        yylex(&yylval, &yylloc)
  467. #endif
  468. #else /* not YYLSP_NEEDED */
  469. #ifdef YYLEX_PARAM
  470. #define YYLEX        yylex(&yylval, YYLEX_PARAM)
  471. #else
  472. #define YYLEX        yylex(&yylval)
  473. #endif
  474. #endif /* not YYLSP_NEEDED */
  475. #endif
  476.  
  477. /* If nonreentrant, generate the variables here */
  478.  
  479. #ifndef YYPURE
  480.  
  481. int    yychar;            /*  the lookahead symbol        */
  482. YYSTYPE    yylval;            /*  the semantic value of the        */
  483.                 /*  lookahead symbol            */
  484.  
  485. #ifdef YYLSP_NEEDED
  486. YYLTYPE yylloc;            /*  location data for the lookahead    */
  487.                 /*  symbol                */
  488. #endif
  489.  
  490. int yynerrs;            /*  number of parse errors so far       */
  491. #endif  /* not YYPURE */
  492.  
  493. #if YYDEBUG != 0
  494. int yydebug;            /*  nonzero means print parse trace    */
  495. /* Since this is uninitialized, it does not stop multiple parsers
  496.    from coexisting.  */
  497. #endif
  498.  
  499. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  500.  
  501. #ifndef    YYINITDEPTH
  502. #define YYINITDEPTH 200
  503. #endif
  504.  
  505. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  506.     (effective only if the built-in stack extension method is used).  */
  507.  
  508. #if YYMAXDEPTH == 0
  509. #undef YYMAXDEPTH
  510. #endif
  511.  
  512. #ifndef YYMAXDEPTH
  513. #define YYMAXDEPTH 10000
  514. #endif
  515.  
  516. /* Prevent warning if -Wstrict-prototypes.  */
  517. #ifdef __GNUC__
  518. int yyparse (void);
  519. #endif
  520.  
  521. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  522. #define __yy_memcpy(TO,FROM,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  523. #else                /* not GNU C or C++ */
  524. #ifndef __cplusplus
  525.  
  526. /* This is the most reliable way to avoid incompatibilities
  527.    in available built-in functions on various systems.  */
  528. static void
  529. __yy_memcpy (to, from, count)
  530.      char *to;
  531.      char *from;
  532.      int count;
  533. {
  534.   register char *f = from;
  535.   register char *t = to;
  536.   register int i = count;
  537.  
  538.   while (i-- > 0)
  539.     *t++ = *f++;
  540. }
  541.  
  542. #else /* __cplusplus */
  543.  
  544. /* This is the most reliable way to avoid incompatibilities
  545.    in available built-in functions on various systems.  */
  546. static void
  547. __yy_memcpy (char *to, char *from, int count)
  548. {
  549.   register char *t = to;
  550.   register char *f = from;
  551.   register int i = count;
  552.  
  553.   while (i-- > 0)
  554.     *t++ = *f++;
  555. }
  556.  
  557. #endif
  558. #endif
  559.  
  560. #line 196 "/p/share/bison.simple"
  561.  
  562. /* The user can define YYPARSE_PARAM as the name of an argument to be passed
  563.    into yyparse.  The argument should have type void *.
  564.    It should actually point to an object.
  565.    Grammar actions can access the variable by casting it
  566.    to the proper pointer type.  */
  567.  
  568. #ifdef YYPARSE_PARAM
  569. #ifdef __cplusplus
  570. #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
  571. #define YYPARSE_PARAM_DECL
  572. #else /* not __cplusplus */
  573. #define YYPARSE_PARAM_ARG YYPARSE_PARAM
  574. #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
  575. #endif /* not __cplusplus */
  576. #else /* not YYPARSE_PARAM */
  577. #define YYPARSE_PARAM_ARG
  578. #define YYPARSE_PARAM_DECL
  579. #endif /* not YYPARSE_PARAM */
  580.  
  581. int
  582. yyparse(YYPARSE_PARAM_ARG)
  583.      YYPARSE_PARAM_DECL
  584. {
  585.   register int yystate;
  586.   register int yyn;
  587.   register short *yyssp;
  588.   register YYSTYPE *yyvsp;
  589.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  590.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  591.  
  592.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  593.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  594.  
  595.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  596.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  597.  
  598. #ifdef YYLSP_NEEDED
  599.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  600.   YYLTYPE *yyls = yylsa;
  601.   YYLTYPE *yylsp;
  602.  
  603. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  604. #else
  605. #define YYPOPSTACK   (yyvsp--, yyssp--)
  606. #endif
  607.  
  608.   int yystacksize = YYINITDEPTH;
  609.  
  610. #ifdef YYPURE
  611.   int yychar;
  612.   YYSTYPE yylval;
  613.   int yynerrs;
  614. #ifdef YYLSP_NEEDED
  615.   YYLTYPE yylloc;
  616. #endif
  617. #endif
  618.  
  619.   YYSTYPE yyval;        /*  the variable used to return        */
  620.                 /*  semantic values from the action    */
  621.                 /*  routines                */
  622.  
  623.   int yylen;
  624.  
  625. #if YYDEBUG != 0
  626.   if (yydebug)
  627.     fprintf(stderr, "Starting parse\n");
  628. #endif
  629.  
  630.   yystate = 0;
  631.   yyerrstatus = 0;
  632.   yynerrs = 0;
  633.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  634.  
  635.   /* Initialize stack pointers.
  636.      Waste one element of value and location stack
  637.      so that they stay on the same level as the state stack.
  638.      The wasted elements are never initialized.  */
  639.  
  640.   yyssp = yyss - 1;
  641.   yyvsp = yyvs;
  642. #ifdef YYLSP_NEEDED
  643.   yylsp = yyls;
  644. #endif
  645.  
  646. /* Push a new state, which is found in  yystate  .  */
  647. /* In all cases, when you get here, the value and location stacks
  648.    have just been pushed. so pushing a state here evens the stacks.  */
  649. yynewstate:
  650.  
  651.   *++yyssp = yystate;
  652.  
  653.   if (yyssp >= yyss + yystacksize - 1)
  654.     {
  655.       /* Give user a chance to reallocate the stack */
  656.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  657.       YYSTYPE *yyvs1 = yyvs;
  658.       short *yyss1 = yyss;
  659. #ifdef YYLSP_NEEDED
  660.       YYLTYPE *yyls1 = yyls;
  661. #endif
  662.  
  663.       /* Get the current used size of the three stacks, in elements.  */
  664.       int size = yyssp - yyss + 1;
  665.  
  666. #ifdef yyoverflow
  667.       /* Each stack pointer address is followed by the size of
  668.      the data in use in that stack, in bytes.  */
  669. #ifdef YYLSP_NEEDED
  670.       /* This used to be a conditional around just the two extra args,
  671.      but that might be undefined if yyoverflow is a macro.  */
  672.       yyoverflow("parser stack overflow",
  673.          &yyss1, size * sizeof (*yyssp),
  674.          &yyvs1, size * sizeof (*yyvsp),
  675.          &yyls1, size * sizeof (*yylsp),
  676.          &yystacksize);
  677. #else
  678.       yyoverflow("parser stack overflow",
  679.          &yyss1, size * sizeof (*yyssp),
  680.          &yyvs1, size * sizeof (*yyvsp),
  681.          &yystacksize);
  682. #endif
  683.  
  684.       yyss = yyss1; yyvs = yyvs1;
  685. #ifdef YYLSP_NEEDED
  686.       yyls = yyls1;
  687. #endif
  688. #else /* no yyoverflow */
  689.       /* Extend the stack our own way.  */
  690.       if (yystacksize >= YYMAXDEPTH)
  691.     {
  692.       yyerror("parser stack overflow");
  693.       return 2;
  694.     }
  695.       yystacksize *= 2;
  696.       if (yystacksize > YYMAXDEPTH)
  697.     yystacksize = YYMAXDEPTH;
  698.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  699.       __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
  700.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  701.       __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
  702. #ifdef YYLSP_NEEDED
  703.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  704.       __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
  705. #endif
  706. #endif /* no yyoverflow */
  707.  
  708.       yyssp = yyss + size - 1;
  709.       yyvsp = yyvs + size - 1;
  710. #ifdef YYLSP_NEEDED
  711.       yylsp = yyls + size - 1;
  712. #endif
  713.  
  714. #if YYDEBUG != 0
  715.       if (yydebug)
  716.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  717. #endif
  718.  
  719.       if (yyssp >= yyss + yystacksize - 1)
  720.     YYABORT;
  721.     }
  722.  
  723. #if YYDEBUG != 0
  724.   if (yydebug)
  725.     fprintf(stderr, "Entering state %d\n", yystate);
  726. #endif
  727.  
  728.   goto yybackup;
  729.  yybackup:
  730.  
  731. /* Do appropriate processing given the current state.  */
  732. /* Read a lookahead token if we need one and don't already have one.  */
  733. /* yyresume: */
  734.  
  735.   /* First try to decide what to do without reference to lookahead token.  */
  736.  
  737.   yyn = yypact[yystate];
  738.   if (yyn == YYFLAG)
  739.     goto yydefault;
  740.  
  741.   /* Not known => get a lookahead token if don't already have one.  */
  742.  
  743.   /* yychar is either YYEMPTY or YYEOF
  744.      or a valid token in external form.  */
  745.  
  746.   if (yychar == YYEMPTY)
  747.     {
  748. #if YYDEBUG != 0
  749.       if (yydebug)
  750.     fprintf(stderr, "Reading a token: ");
  751. #endif
  752.       yychar = YYLEX;
  753.     }
  754.  
  755.   /* Convert token to internal form (in yychar1) for indexing tables with */
  756.  
  757.   if (yychar <= 0)        /* This means end of input. */
  758.     {
  759.       yychar1 = 0;
  760.       yychar = YYEOF;        /* Don't call YYLEX any more */
  761.  
  762. #if YYDEBUG != 0
  763.       if (yydebug)
  764.     fprintf(stderr, "Now at end of input.\n");
  765. #endif
  766.     }
  767.   else
  768.     {
  769.       yychar1 = YYTRANSLATE(yychar);
  770.  
  771. #if YYDEBUG != 0
  772.       if (yydebug)
  773.     {
  774.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  775.       /* Give the individual parser a way to print the precise meaning
  776.          of a token, for further debugging info.  */
  777. #ifdef YYPRINT
  778.       YYPRINT (stderr, yychar, yylval);
  779. #endif
  780.       fprintf (stderr, ")\n");
  781.     }
  782. #endif
  783.     }
  784.  
  785.   yyn += yychar1;
  786.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  787.     goto yydefault;
  788.  
  789.   yyn = yytable[yyn];
  790.  
  791.   /* yyn is what to do for this token type in this state.
  792.      Negative => reduce, -yyn is rule number.
  793.      Positive => shift, yyn is new state.
  794.        New state is final state => don't bother to shift,
  795.        just return success.
  796.      0, or most negative number => error.  */
  797.  
  798.   if (yyn < 0)
  799.     {
  800.       if (yyn == YYFLAG)
  801.     goto yyerrlab;
  802.       yyn = -yyn;
  803.       goto yyreduce;
  804.     }
  805.   else if (yyn == 0)
  806.     goto yyerrlab;
  807.  
  808.   if (yyn == YYFINAL)
  809.     YYACCEPT;
  810.  
  811.   /* Shift the lookahead token.  */
  812.  
  813. #if YYDEBUG != 0
  814.   if (yydebug)
  815.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  816. #endif
  817.  
  818.   /* Discard the token being shifted unless it is eof.  */
  819.   if (yychar != YYEOF)
  820.     yychar = YYEMPTY;
  821.  
  822.   *++yyvsp = yylval;
  823. #ifdef YYLSP_NEEDED
  824.   *++yylsp = yylloc;
  825. #endif
  826.  
  827.   /* count tokens shifted since error; after three, turn off error status.  */
  828.   if (yyerrstatus) yyerrstatus--;
  829.  
  830.   yystate = yyn;
  831.   goto yynewstate;
  832.  
  833. /* Do the default action for the current state.  */
  834. yydefault:
  835.  
  836.   yyn = yydefact[yystate];
  837.   if (yyn == 0)
  838.     goto yyerrlab;
  839.  
  840. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  841. yyreduce:
  842.   yylen = yyr2[yyn];
  843.   if (yylen > 0)
  844.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  845.  
  846. #if YYDEBUG != 0
  847.   if (yydebug)
  848.     {
  849.       int i;
  850.  
  851.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  852.            yyn, yyrline[yyn]);
  853.  
  854.       /* Print the symbols being reduced, and their result.  */
  855.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  856.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  857.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  858.     }
  859. #endif
  860.  
  861.  
  862.   switch (yyn) {
  863.  
  864. case 3:
  865. #line 195 "getdate.y"
  866. {
  867.         yyHaveTime++;
  868.     ;
  869.     break;}
  870. case 4:
  871. #line 198 "getdate.y"
  872. {
  873.         yyHaveZone++;
  874.     ;
  875.     break;}
  876. case 5:
  877. #line 201 "getdate.y"
  878. {
  879.         yyHaveDate++;
  880.     ;
  881.     break;}
  882. case 6:
  883. #line 204 "getdate.y"
  884. {
  885.         yyHaveDay++;
  886.     ;
  887.     break;}
  888. case 7:
  889. #line 207 "getdate.y"
  890. {
  891.         yyHaveRel++;
  892.     ;
  893.     break;}
  894. case 9:
  895. #line 213 "getdate.y"
  896. {
  897.         yyHour = yyvsp[-1].Number;
  898.         yyMinutes = 0;
  899.         yySeconds = 0;
  900.         yyMeridian = yyvsp[0].Meridian;
  901.     ;
  902.     break;}
  903. case 10:
  904. #line 219 "getdate.y"
  905. {
  906.         yyHour = yyvsp[-3].Number;
  907.         yyMinutes = yyvsp[-1].Number;
  908.         yySeconds = 0;
  909.         yyMeridian = yyvsp[0].Meridian;
  910.     ;
  911.     break;}
  912. case 11:
  913. #line 225 "getdate.y"
  914. {
  915.         yyHour = yyvsp[-3].Number;
  916.         yyMinutes = yyvsp[-1].Number;
  917.         yyMeridian = MER24;
  918.         yyHaveZone++;
  919.         yyTimezone = (yyvsp[0].Number < 0
  920.               ? -yyvsp[0].Number % 100 + (-yyvsp[0].Number / 100) * 60
  921.               : - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60));
  922.     ;
  923.     break;}
  924. case 12:
  925. #line 234 "getdate.y"
  926. {
  927.         yyHour = yyvsp[-5].Number;
  928.         yyMinutes = yyvsp[-3].Number;
  929.         yySeconds = yyvsp[-1].Number;
  930.         yyMeridian = yyvsp[0].Meridian;
  931.     ;
  932.     break;}
  933. case 13:
  934. #line 240 "getdate.y"
  935. {
  936.         yyHour = yyvsp[-5].Number;
  937.         yyMinutes = yyvsp[-3].Number;
  938.         yySeconds = yyvsp[-1].Number;
  939.         yyMeridian = MER24;
  940.         yyHaveZone++;
  941.         yyTimezone = (yyvsp[0].Number < 0
  942.               ? -yyvsp[0].Number % 100 + (-yyvsp[0].Number / 100) * 60
  943.               : - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60));
  944.     ;
  945.     break;}
  946. case 14:
  947. #line 252 "getdate.y"
  948. {
  949.         yyTimezone = yyvsp[0].Number;
  950.     ;
  951.     break;}
  952. case 15:
  953. #line 255 "getdate.y"
  954. {
  955.         yyTimezone = yyvsp[0].Number - 60;
  956.     ;
  957.     break;}
  958. case 16:
  959. #line 259 "getdate.y"
  960. {
  961.         yyTimezone = yyvsp[-1].Number - 60;
  962.     ;
  963.     break;}
  964. case 17:
  965. #line 264 "getdate.y"
  966. {
  967.         yyDayOrdinal = 1;
  968.         yyDayNumber = yyvsp[0].Number;
  969.     ;
  970.     break;}
  971. case 18:
  972. #line 268 "getdate.y"
  973. {
  974.         yyDayOrdinal = 1;
  975.         yyDayNumber = yyvsp[-1].Number;
  976.     ;
  977.     break;}
  978. case 19:
  979. #line 272 "getdate.y"
  980. {
  981.         yyDayOrdinal = yyvsp[-1].Number;
  982.         yyDayNumber = yyvsp[0].Number;
  983.     ;
  984.     break;}
  985. case 20:
  986. #line 278 "getdate.y"
  987. {
  988.         yyMonth = yyvsp[-2].Number;
  989.         yyDay = yyvsp[0].Number;
  990.     ;
  991.     break;}
  992. case 21:
  993. #line 282 "getdate.y"
  994. {
  995.       /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
  996.          The goal in recognizing YYYY/MM/DD is solely to support legacy
  997.          machine-generated dates like those in an RCS log listing.  If
  998.          you want portability, use the ISO 8601 format.  */
  999.       if (yyvsp[-4].Number >= 1000)
  1000.         {
  1001.           yyYear = yyvsp[-4].Number;
  1002.           yyMonth = yyvsp[-2].Number;
  1003.           yyDay = yyvsp[0].Number;
  1004.         }
  1005.       else
  1006.         {
  1007.           yyMonth = yyvsp[-4].Number;
  1008.           yyDay = yyvsp[-2].Number;
  1009.           yyYear = yyvsp[0].Number;
  1010.         }
  1011.     ;
  1012.     break;}
  1013. case 22:
  1014. #line 300 "getdate.y"
  1015. {
  1016.         /* ISO 8601 format.  yyyy-mm-dd.  */
  1017.         yyYear = yyvsp[-2].Number;
  1018.         yyMonth = -yyvsp[-1].Number;
  1019.         yyDay = -yyvsp[0].Number;
  1020.     ;
  1021.     break;}
  1022. case 23:
  1023. #line 306 "getdate.y"
  1024. {
  1025.         /* e.g. 17-JUN-1992.  */
  1026.         yyDay = yyvsp[-2].Number;
  1027.         yyMonth = yyvsp[-1].Number;
  1028.         yyYear = -yyvsp[0].Number;
  1029.     ;
  1030.     break;}
  1031. case 24:
  1032. #line 312 "getdate.y"
  1033. {
  1034.         yyMonth = yyvsp[-1].Number;
  1035.         yyDay = yyvsp[0].Number;
  1036.     ;
  1037.     break;}
  1038. case 25:
  1039. #line 316 "getdate.y"
  1040. {
  1041.         yyMonth = yyvsp[-3].Number;
  1042.         yyDay = yyvsp[-2].Number;
  1043.         yyYear = yyvsp[0].Number;
  1044.     ;
  1045.     break;}
  1046. case 26:
  1047. #line 321 "getdate.y"
  1048. {
  1049.         yyMonth = yyvsp[0].Number;
  1050.         yyDay = yyvsp[-1].Number;
  1051.     ;
  1052.     break;}
  1053. case 27:
  1054. #line 325 "getdate.y"
  1055. {
  1056.         yyMonth = yyvsp[-1].Number;
  1057.         yyDay = yyvsp[-2].Number;
  1058.         yyYear = yyvsp[0].Number;
  1059.     ;
  1060.     break;}
  1061. case 28:
  1062. #line 332 "getdate.y"
  1063. {
  1064.         yyRelSeconds = -yyRelSeconds;
  1065.         yyRelMinutes = -yyRelMinutes;
  1066.         yyRelHour = -yyRelHour;
  1067.         yyRelDay = -yyRelDay;
  1068.         yyRelMonth = -yyRelMonth;
  1069.         yyRelYear = -yyRelYear;
  1070.     ;
  1071.     break;}
  1072. case 30:
  1073. #line 343 "getdate.y"
  1074. {
  1075.         yyRelYear += yyvsp[-1].Number * yyvsp[0].Number;
  1076.     ;
  1077.     break;}
  1078. case 31:
  1079. #line 346 "getdate.y"
  1080. {
  1081.         yyRelYear += yyvsp[-1].Number * yyvsp[0].Number;
  1082.     ;
  1083.     break;}
  1084. case 32:
  1085. #line 349 "getdate.y"
  1086. {
  1087.         yyRelYear++;
  1088.     ;
  1089.     break;}
  1090. case 33:
  1091. #line 352 "getdate.y"
  1092. {
  1093.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1094.     ;
  1095.     break;}
  1096. case 34:
  1097. #line 355 "getdate.y"
  1098. {
  1099.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1100.     ;
  1101.     break;}
  1102. case 35:
  1103. #line 358 "getdate.y"
  1104. {
  1105.         yyRelMonth++;
  1106.     ;
  1107.     break;}
  1108. case 36:
  1109. #line 361 "getdate.y"
  1110. {
  1111.         yyRelDay += yyvsp[-1].Number * yyvsp[0].Number;
  1112.     ;
  1113.     break;}
  1114. case 37:
  1115. #line 364 "getdate.y"
  1116. {
  1117.         yyRelDay += yyvsp[-1].Number * yyvsp[0].Number;
  1118.     ;
  1119.     break;}
  1120. case 38:
  1121. #line 367 "getdate.y"
  1122. {
  1123.         yyRelDay++;
  1124.     ;
  1125.     break;}
  1126. case 39:
  1127. #line 370 "getdate.y"
  1128. {
  1129.         yyRelHour += yyvsp[-1].Number * yyvsp[0].Number;
  1130.     ;
  1131.     break;}
  1132. case 40:
  1133. #line 373 "getdate.y"
  1134. {
  1135.         yyRelHour += yyvsp[-1].Number * yyvsp[0].Number;
  1136.     ;
  1137.     break;}
  1138. case 41:
  1139. #line 376 "getdate.y"
  1140. {
  1141.         yyRelHour++;
  1142.     ;
  1143.     break;}
  1144. case 42:
  1145. #line 379 "getdate.y"
  1146. {
  1147.         yyRelMinutes += yyvsp[-1].Number * yyvsp[0].Number;
  1148.     ;
  1149.     break;}
  1150. case 43:
  1151. #line 382 "getdate.y"
  1152. {
  1153.         yyRelMinutes += yyvsp[-1].Number * yyvsp[0].Number;
  1154.     ;
  1155.     break;}
  1156. case 44:
  1157. #line 385 "getdate.y"
  1158. {
  1159.         yyRelMinutes++;
  1160.     ;
  1161.     break;}
  1162. case 45:
  1163. #line 388 "getdate.y"
  1164. {
  1165.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
  1166.     ;
  1167.     break;}
  1168. case 46:
  1169. #line 391 "getdate.y"
  1170. {
  1171.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number;
  1172.     ;
  1173.     break;}
  1174. case 47:
  1175. #line 394 "getdate.y"
  1176. {
  1177.         yyRelSeconds++;
  1178.     ;
  1179.     break;}
  1180. case 48:
  1181. #line 400 "getdate.y"
  1182. {
  1183.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1184.           yyYear = yyvsp[0].Number;
  1185.         else
  1186.           {
  1187.         if (yyvsp[0].Number>10000)
  1188.           {
  1189.             yyHaveDate++;
  1190.             yyDay= (yyvsp[0].Number)%100;
  1191.             yyMonth= (yyvsp[0].Number/100)%100;
  1192.             yyYear = yyvsp[0].Number/10000;
  1193.           }
  1194.         else
  1195.           {
  1196.             yyHaveTime++;
  1197.             if (yyvsp[0].Number < 100)
  1198.               {
  1199.             yyHour = yyvsp[0].Number;
  1200.             yyMinutes = 0;
  1201.               }
  1202.             else
  1203.               {
  1204.                 yyHour = yyvsp[0].Number / 100;
  1205.                 yyMinutes = yyvsp[0].Number % 100;
  1206.               }
  1207.             yySeconds = 0;
  1208.             yyMeridian = MER24;
  1209.           }
  1210.           }
  1211.       ;
  1212.     break;}
  1213. case 49:
  1214. #line 433 "getdate.y"
  1215. {
  1216.         yyval.Meridian = MER24;
  1217.       ;
  1218.     break;}
  1219. case 50:
  1220. #line 437 "getdate.y"
  1221. {
  1222.         yyval.Meridian = yyvsp[0].Meridian;
  1223.       ;
  1224.     break;}
  1225. }
  1226.    /* the action file gets copied in in place of this dollarsign */
  1227. #line 498 "/p/share/bison.simple"
  1228.  
  1229.   yyvsp -= yylen;
  1230.   yyssp -= yylen;
  1231. #ifdef YYLSP_NEEDED
  1232.   yylsp -= yylen;
  1233. #endif
  1234.  
  1235. #if YYDEBUG != 0
  1236.   if (yydebug)
  1237.     {
  1238.       short *ssp1 = yyss - 1;
  1239.       fprintf (stderr, "state stack now");
  1240.       while (ssp1 != yyssp)
  1241.     fprintf (stderr, " %d", *++ssp1);
  1242.       fprintf (stderr, "\n");
  1243.     }
  1244. #endif
  1245.  
  1246.   *++yyvsp = yyval;
  1247.  
  1248. #ifdef YYLSP_NEEDED
  1249.   yylsp++;
  1250.   if (yylen == 0)
  1251.     {
  1252.       yylsp->first_line = yylloc.first_line;
  1253.       yylsp->first_column = yylloc.first_column;
  1254.       yylsp->last_line = (yylsp-1)->last_line;
  1255.       yylsp->last_column = (yylsp-1)->last_column;
  1256.       yylsp->text = 0;
  1257.     }
  1258.   else
  1259.     {
  1260.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1261.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1262.     }
  1263. #endif
  1264.  
  1265.   /* Now "shift" the result of the reduction.
  1266.      Determine what state that goes to,
  1267.      based on the state we popped back to
  1268.      and the rule number reduced by.  */
  1269.  
  1270.   yyn = yyr1[yyn];
  1271.  
  1272.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1273.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1274.     yystate = yytable[yystate];
  1275.   else
  1276.     yystate = yydefgoto[yyn - YYNTBASE];
  1277.  
  1278.   goto yynewstate;
  1279.  
  1280. yyerrlab:   /* here on detecting error */
  1281.  
  1282.   if (! yyerrstatus)
  1283.     /* If not already recovering from an error, report this error.  */
  1284.     {
  1285.       ++yynerrs;
  1286.  
  1287. #ifdef YYERROR_VERBOSE
  1288.       yyn = yypact[yystate];
  1289.  
  1290.       if (yyn > YYFLAG && yyn < YYLAST)
  1291.     {
  1292.       int size = 0;
  1293.       char *msg;
  1294.       int x, count;
  1295.  
  1296.       count = 0;
  1297.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1298.       for (x = (yyn < 0 ? -yyn : 0);
  1299.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1300.         if (yycheck[x + yyn] == x)
  1301.           size += strlen(yytname[x]) + 15, count++;
  1302.       msg = (char *) malloc(size + 15);
  1303.       if (msg != 0)
  1304.         {
  1305.           strcpy(msg, "parse error");
  1306.  
  1307.           if (count < 5)
  1308.         {
  1309.           count = 0;
  1310.           for (x = (yyn < 0 ? -yyn : 0);
  1311.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1312.             if (yycheck[x + yyn] == x)
  1313.               {
  1314.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1315.             strcat(msg, yytname[x]);
  1316.             strcat(msg, "'");
  1317.             count++;
  1318.               }
  1319.         }
  1320.           yyerror(msg);
  1321.           free(msg);
  1322.         }
  1323.       else
  1324.         yyerror ("parse error; also virtual memory exceeded");
  1325.     }
  1326.       else
  1327. #endif /* YYERROR_VERBOSE */
  1328.     yyerror("parse error");
  1329.     }
  1330.  
  1331.   goto yyerrlab1;
  1332. yyerrlab1:   /* here on error raised explicitly by an action */
  1333.  
  1334.   if (yyerrstatus == 3)
  1335.     {
  1336.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1337.  
  1338.       /* return failure if at end of input */
  1339.       if (yychar == YYEOF)
  1340.     YYABORT;
  1341.  
  1342. #if YYDEBUG != 0
  1343.       if (yydebug)
  1344.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1345. #endif
  1346.  
  1347.       yychar = YYEMPTY;
  1348.     }
  1349.  
  1350.   /* Else will try to reuse lookahead token
  1351.      after shifting the error token.  */
  1352.  
  1353.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1354.  
  1355.   goto yyerrhandle;
  1356.  
  1357. yyerrdefault:  /* current state does not do anything special for the error token. */
  1358.  
  1359. #if 0
  1360.   /* This is wrong; only states that explicitly want error tokens
  1361.      should shift them.  */
  1362.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1363.   if (yyn) goto yydefault;
  1364. #endif
  1365.  
  1366. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1367.  
  1368.   if (yyssp == yyss) YYABORT;
  1369.   yyvsp--;
  1370.   yystate = *--yyssp;
  1371. #ifdef YYLSP_NEEDED
  1372.   yylsp--;
  1373. #endif
  1374.  
  1375. #if YYDEBUG != 0
  1376.   if (yydebug)
  1377.     {
  1378.       short *ssp1 = yyss - 1;
  1379.       fprintf (stderr, "Error: state stack now");
  1380.       while (ssp1 != yyssp)
  1381.     fprintf (stderr, " %d", *++ssp1);
  1382.       fprintf (stderr, "\n");
  1383.     }
  1384. #endif
  1385.  
  1386. yyerrhandle:
  1387.  
  1388.   yyn = yypact[yystate];
  1389.   if (yyn == YYFLAG)
  1390.     goto yyerrdefault;
  1391.  
  1392.   yyn += YYTERROR;
  1393.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1394.     goto yyerrdefault;
  1395.  
  1396.   yyn = yytable[yyn];
  1397.   if (yyn < 0)
  1398.     {
  1399.       if (yyn == YYFLAG)
  1400.     goto yyerrpop;
  1401.       yyn = -yyn;
  1402.       goto yyreduce;
  1403.     }
  1404.   else if (yyn == 0)
  1405.     goto yyerrpop;
  1406.  
  1407.   if (yyn == YYFINAL)
  1408.     YYACCEPT;
  1409.  
  1410. #if YYDEBUG != 0
  1411.   if (yydebug)
  1412.     fprintf(stderr, "Shifting error token, ");
  1413. #endif
  1414.  
  1415.   *++yyvsp = yylval;
  1416. #ifdef YYLSP_NEEDED
  1417.   *++yylsp = yylloc;
  1418. #endif
  1419.  
  1420.   yystate = yyn;
  1421.   goto yynewstate;
  1422. }
  1423. #line 442 "getdate.y"
  1424.  
  1425.  
  1426. /* Month and day table. */
  1427. static TABLE const MonthDayTable[] = {
  1428.     { "january",    tMONTH,  1 },
  1429.     { "february",    tMONTH,  2 },
  1430.     { "march",        tMONTH,  3 },
  1431.     { "april",        tMONTH,  4 },
  1432.     { "may",        tMONTH,  5 },
  1433.     { "june",        tMONTH,  6 },
  1434.     { "july",        tMONTH,  7 },
  1435.     { "august",        tMONTH,  8 },
  1436.     { "september",    tMONTH,  9 },
  1437.     { "sept",        tMONTH,  9 },
  1438.     { "october",    tMONTH, 10 },
  1439.     { "november",    tMONTH, 11 },
  1440.     { "december",    tMONTH, 12 },
  1441.     { "sunday",        tDAY, 0 },
  1442.     { "monday",        tDAY, 1 },
  1443.     { "tuesday",    tDAY, 2 },
  1444.     { "tues",        tDAY, 2 },
  1445.     { "wednesday",    tDAY, 3 },
  1446.     { "wednes",        tDAY, 3 },
  1447.     { "thursday",    tDAY, 4 },
  1448.     { "thur",        tDAY, 4 },
  1449.     { "thurs",        tDAY, 4 },
  1450.     { "friday",        tDAY, 5 },
  1451.     { "saturday",    tDAY, 6 },
  1452.     { NULL }
  1453. };
  1454.  
  1455. /* Time units table. */
  1456. static TABLE const UnitsTable[] = {
  1457.     { "year",        tYEAR_UNIT,    1 },
  1458.     { "month",        tMONTH_UNIT,    1 },
  1459.     { "fortnight",    tDAY_UNIT,    14 },
  1460.     { "week",        tDAY_UNIT,    7 },
  1461.     { "day",        tDAY_UNIT,    1 },
  1462.     { "hour",        tHOUR_UNIT,    1 },
  1463.     { "minute",        tMINUTE_UNIT,    1 },
  1464.     { "min",        tMINUTE_UNIT,    1 },
  1465.     { "second",        tSEC_UNIT,    1 },
  1466.     { "sec",        tSEC_UNIT,    1 },
  1467.     { NULL }
  1468. };
  1469.  
  1470. /* Assorted relative-time words. */
  1471. static TABLE const OtherTable[] = {
  1472.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1473.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1474.     { "today",        tMINUTE_UNIT,    0 },
  1475.     { "now",        tMINUTE_UNIT,    0 },
  1476.     { "last",        tUNUMBER,    -1 },
  1477.     { "this",        tMINUTE_UNIT,    0 },
  1478.     { "next",        tUNUMBER,    2 },
  1479.     { "first",        tUNUMBER,    1 },
  1480. /*  { "second",        tUNUMBER,    2 }, */
  1481.     { "third",        tUNUMBER,    3 },
  1482.     { "fourth",        tUNUMBER,    4 },
  1483.     { "fifth",        tUNUMBER,    5 },
  1484.     { "sixth",        tUNUMBER,    6 },
  1485.     { "seventh",    tUNUMBER,    7 },
  1486.     { "eighth",        tUNUMBER,    8 },
  1487.     { "ninth",        tUNUMBER,    9 },
  1488.     { "tenth",        tUNUMBER,    10 },
  1489.     { "eleventh",    tUNUMBER,    11 },
  1490.     { "twelfth",    tUNUMBER,    12 },
  1491.     { "ago",        tAGO,    1 },
  1492.     { NULL }
  1493. };
  1494.  
  1495. /* The timezone table. */
  1496. static TABLE const TimezoneTable[] = {
  1497.     { "gmt",    tZONE,     HOUR ( 0) },    /* Greenwich Mean */
  1498.     { "ut",    tZONE,     HOUR ( 0) },    /* Universal (Coordinated) */
  1499.     { "utc",    tZONE,     HOUR ( 0) },
  1500.     { "wet",    tZONE,     HOUR ( 0) },    /* Western European */
  1501.     { "bst",    tDAYZONE,  HOUR ( 0) },    /* British Summer */
  1502.     { "wat",    tZONE,     HOUR ( 1) },    /* West Africa */
  1503.     { "at",    tZONE,     HOUR ( 2) },    /* Azores */
  1504. #if    0
  1505.     /* For completeness.  BST is also British Summer, and GST is
  1506.      * also Guam Standard. */
  1507.     { "bst",    tZONE,     HOUR ( 3) },    /* Brazil Standard */
  1508.     { "gst",    tZONE,     HOUR ( 3) },    /* Greenland Standard */
  1509. #endif
  1510. #if 0
  1511.     { "nft",    tZONE,     HOUR (3.5) },    /* Newfoundland */
  1512.     { "nst",    tZONE,     HOUR (3.5) },    /* Newfoundland Standard */
  1513.     { "ndt",    tDAYZONE,  HOUR (3.5) },    /* Newfoundland Daylight */
  1514. #endif
  1515.     { "ast",    tZONE,     HOUR ( 4) },    /* Atlantic Standard */
  1516.     { "adt",    tDAYZONE,  HOUR ( 4) },    /* Atlantic Daylight */
  1517.     { "est",    tZONE,     HOUR ( 5) },    /* Eastern Standard */
  1518.     { "edt",    tDAYZONE,  HOUR ( 5) },    /* Eastern Daylight */
  1519.     { "cst",    tZONE,     HOUR ( 6) },    /* Central Standard */
  1520.     { "cdt",    tDAYZONE,  HOUR ( 6) },    /* Central Daylight */
  1521.     { "mst",    tZONE,     HOUR ( 7) },    /* Mountain Standard */
  1522.     { "mdt",    tDAYZONE,  HOUR ( 7) },    /* Mountain Daylight */
  1523.     { "pst",    tZONE,     HOUR ( 8) },    /* Pacific Standard */
  1524.     { "pdt",    tDAYZONE,  HOUR ( 8) },    /* Pacific Daylight */
  1525.     { "yst",    tZONE,     HOUR ( 9) },    /* Yukon Standard */
  1526.     { "ydt",    tDAYZONE,  HOUR ( 9) },    /* Yukon Daylight */
  1527.     { "hst",    tZONE,     HOUR (10) },    /* Hawaii Standard */
  1528.     { "hdt",    tDAYZONE,  HOUR (10) },    /* Hawaii Daylight */
  1529.     { "cat",    tZONE,     HOUR (10) },    /* Central Alaska */
  1530.     { "ahst",    tZONE,     HOUR (10) },    /* Alaska-Hawaii Standard */
  1531.     { "nt",    tZONE,     HOUR (11) },    /* Nome */
  1532.     { "idlw",    tZONE,     HOUR (12) },    /* International Date Line West */
  1533.     { "cet",    tZONE,     -HOUR (1) },    /* Central European */
  1534.     { "met",    tZONE,     -HOUR (1) },    /* Middle European */
  1535.     { "mewt",    tZONE,     -HOUR (1) },    /* Middle European Winter */
  1536.     { "mest",    tDAYZONE,  -HOUR (1) },    /* Middle European Summer */
  1537.     { "mesz",    tDAYZONE,  -HOUR (1) },    /* Middle European Summer */
  1538.     { "swt",    tZONE,     -HOUR (1) },    /* Swedish Winter */
  1539.     { "sst",    tDAYZONE,  -HOUR (1) },    /* Swedish Summer */
  1540.     { "fwt",    tZONE,     -HOUR (1) },    /* French Winter */
  1541.     { "fst",    tDAYZONE,  -HOUR (1) },    /* French Summer */
  1542.     { "eet",    tZONE,     -HOUR (2) },    /* Eastern Europe, USSR Zone 1 */
  1543.     { "bt",    tZONE,     -HOUR (3) },    /* Baghdad, USSR Zone 2 */
  1544. #if 0
  1545.     { "it",    tZONE,     -HOUR (3.5) },/* Iran */
  1546. #endif
  1547.     { "zp4",    tZONE,     -HOUR (4) },    /* USSR Zone 3 */
  1548.     { "zp5",    tZONE,     -HOUR (5) },    /* USSR Zone 4 */
  1549. #if 0
  1550.     { "ist",    tZONE,     -HOUR (5.5) },/* Indian Standard */
  1551. #endif
  1552.     { "zp6",    tZONE,     -HOUR (6) },    /* USSR Zone 5 */
  1553. #if    0
  1554.     /* For completeness.  NST is also Newfoundland Standard, and SST is
  1555.      * also Swedish Summer. */
  1556.     { "nst",    tZONE,     -HOUR (6.5) },/* North Sumatra */
  1557.     { "sst",    tZONE,     -HOUR (7) },    /* South Sumatra, USSR Zone 6 */
  1558. #endif    /* 0 */
  1559.     { "wast",    tZONE,     -HOUR (7) },    /* West Australian Standard */
  1560.     { "wadt",    tDAYZONE,  -HOUR (7) },    /* West Australian Daylight */
  1561. #if 0
  1562.     { "jt",    tZONE,     -HOUR (7.5) },/* Java (3pm in Cronusland!) */
  1563. #endif
  1564.     { "cct",    tZONE,     -HOUR (8) },    /* China Coast, USSR Zone 7 */
  1565.     { "jst",    tZONE,     -HOUR (9) },    /* Japan Standard, USSR Zone 8 */
  1566. #if 0
  1567.     { "cast",    tZONE,     -HOUR (9.5) },/* Central Australian Standard */
  1568.     { "cadt",    tDAYZONE,  -HOUR (9.5) },/* Central Australian Daylight */
  1569. #endif
  1570.     { "east",    tZONE,     -HOUR (10) },    /* Eastern Australian Standard */
  1571.     { "eadt",    tDAYZONE,  -HOUR (10) },    /* Eastern Australian Daylight */
  1572.     { "gst",    tZONE,     -HOUR (10) },    /* Guam Standard, USSR Zone 9 */
  1573.     { "nzt",    tZONE,     -HOUR (12) },    /* New Zealand */
  1574.     { "nzst",    tZONE,     -HOUR (12) },    /* New Zealand Standard */
  1575.     { "nzdt",    tDAYZONE,  -HOUR (12) },    /* New Zealand Daylight */
  1576.     { "idle",    tZONE,     -HOUR (12) },    /* International Date Line East */
  1577.     {  NULL  }
  1578. };
  1579.  
  1580. /* Military timezone table. */
  1581. static TABLE const MilitaryTable[] = {
  1582.     { "a",    tZONE,    HOUR (  1) },
  1583.     { "b",    tZONE,    HOUR (  2) },
  1584.     { "c",    tZONE,    HOUR (  3) },
  1585.     { "d",    tZONE,    HOUR (  4) },
  1586.     { "e",    tZONE,    HOUR (  5) },
  1587.     { "f",    tZONE,    HOUR (  6) },
  1588.     { "g",    tZONE,    HOUR (  7) },
  1589.     { "h",    tZONE,    HOUR (  8) },
  1590.     { "i",    tZONE,    HOUR (  9) },
  1591.     { "k",    tZONE,    HOUR ( 10) },
  1592.     { "l",    tZONE,    HOUR ( 11) },
  1593.     { "m",    tZONE,    HOUR ( 12) },
  1594.     { "n",    tZONE,    HOUR (- 1) },
  1595.     { "o",    tZONE,    HOUR (- 2) },
  1596.     { "p",    tZONE,    HOUR (- 3) },
  1597.     { "q",    tZONE,    HOUR (- 4) },
  1598.     { "r",    tZONE,    HOUR (- 5) },
  1599.     { "s",    tZONE,    HOUR (- 6) },
  1600.     { "t",    tZONE,    HOUR (- 7) },
  1601.     { "u",    tZONE,    HOUR (- 8) },
  1602.     { "v",    tZONE,    HOUR (- 9) },
  1603.     { "w",    tZONE,    HOUR (-10) },
  1604.     { "x",    tZONE,    HOUR (-11) },
  1605.     { "y",    tZONE,    HOUR (-12) },
  1606.     { "z",    tZONE,    HOUR (  0) },
  1607.     { NULL }
  1608. };
  1609.  
  1610.  
  1611.  
  1612.  
  1613. /* ARGSUSED */
  1614. static int
  1615. yyerror (s)
  1616.      char *s;
  1617. {
  1618.   return 0;
  1619. }
  1620.  
  1621. static int
  1622. ToHour (Hours, Meridian)
  1623.      int Hours;
  1624.      MERIDIAN Meridian;
  1625. {
  1626.   switch (Meridian)
  1627.     {
  1628.     case MER24:
  1629.       if (Hours < 0 || Hours > 23)
  1630.     return -1;
  1631.       return Hours;
  1632.     case MERam:
  1633.       if (Hours < 1 || Hours > 12)
  1634.     return -1;
  1635.       if (Hours == 12)
  1636.     Hours = 0;
  1637.       return Hours;
  1638.     case MERpm:
  1639.       if (Hours < 1 || Hours > 12)
  1640.     return -1;
  1641.       if (Hours == 12)
  1642.     Hours = 0;
  1643.       return Hours + 12;
  1644.     default:
  1645.       abort ();
  1646.     }
  1647.   /* NOTREACHED */
  1648. }
  1649.  
  1650. static int
  1651. ToYear (Year)
  1652.      int Year;
  1653. {
  1654.   if (Year < 0)
  1655.     Year = -Year;
  1656.  
  1657.   /* XPG4 suggests that years 00-68 map to 2000-2068, and
  1658.      years 69-99 map to 1969-1999.  */
  1659.   if (Year < 69)
  1660.     Year += 2000;
  1661.   else if (Year < 100)
  1662.     Year += 1900;
  1663.  
  1664.   return Year;
  1665. }
  1666.  
  1667. static int
  1668. LookupWord (buff)
  1669.      char *buff;
  1670. {
  1671.   register char *p;
  1672.   register char *q;
  1673.   register const TABLE *tp;
  1674.   int i;
  1675.   int abbrev;
  1676.  
  1677.   /* Make it lowercase. */
  1678.   for (p = buff; *p; p++)
  1679.     if (ISUPPER (*p))
  1680.       *p = tolower (*p);
  1681.  
  1682.   if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
  1683.     {
  1684.       yylval.Meridian = MERam;
  1685.       return tMERIDIAN;
  1686.     }
  1687.   if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
  1688.     {
  1689.       yylval.Meridian = MERpm;
  1690.       return tMERIDIAN;
  1691.     }
  1692.  
  1693.   /* See if we have an abbreviation for a month. */
  1694.   if (strlen (buff) == 3)
  1695.     abbrev = 1;
  1696.   else if (strlen (buff) == 4 && buff[3] == '.')
  1697.     {
  1698.       abbrev = 1;
  1699.       buff[3] = '\0';
  1700.     }
  1701.   else
  1702.     abbrev = 0;
  1703.  
  1704.   for (tp = MonthDayTable; tp->name; tp++)
  1705.     {
  1706.       if (abbrev)
  1707.     {
  1708.       if (strncmp (buff, tp->name, 3) == 0)
  1709.         {
  1710.           yylval.Number = tp->value;
  1711.           return tp->type;
  1712.         }
  1713.     }
  1714.       else if (strcmp (buff, tp->name) == 0)
  1715.     {
  1716.       yylval.Number = tp->value;
  1717.       return tp->type;
  1718.     }
  1719.     }
  1720.  
  1721.   for (tp = TimezoneTable; tp->name; tp++)
  1722.     if (strcmp (buff, tp->name) == 0)
  1723.       {
  1724.     yylval.Number = tp->value;
  1725.     return tp->type;
  1726.       }
  1727.  
  1728.   if (strcmp (buff, "dst") == 0)
  1729.     return tDST;
  1730.  
  1731.   for (tp = UnitsTable; tp->name; tp++)
  1732.     if (strcmp (buff, tp->name) == 0)
  1733.       {
  1734.     yylval.Number = tp->value;
  1735.     return tp->type;
  1736.       }
  1737.  
  1738.   /* Strip off any plural and try the units table again. */
  1739.   i = strlen (buff) - 1;
  1740.   if (buff[i] == 's')
  1741.     {
  1742.       buff[i] = '\0';
  1743.       for (tp = UnitsTable; tp->name; tp++)
  1744.     if (strcmp (buff, tp->name) == 0)
  1745.       {
  1746.         yylval.Number = tp->value;
  1747.         return tp->type;
  1748.       }
  1749.       buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1750.     }
  1751.  
  1752.   for (tp = OtherTable; tp->name; tp++)
  1753.     if (strcmp (buff, tp->name) == 0)
  1754.       {
  1755.     yylval.Number = tp->value;
  1756.     return tp->type;
  1757.       }
  1758.  
  1759.   /* Military timezones. */
  1760.   if (buff[1] == '\0' && ISALPHA (*buff))
  1761.     {
  1762.       for (tp = MilitaryTable; tp->name; tp++)
  1763.     if (strcmp (buff, tp->name) == 0)
  1764.       {
  1765.         yylval.Number = tp->value;
  1766.         return tp->type;
  1767.       }
  1768.     }
  1769.  
  1770.   /* Drop out any periods and try the timezone table again. */
  1771.   for (i = 0, p = q = buff; *q; q++)
  1772.     if (*q != '.')
  1773.       *p++ = *q;
  1774.     else
  1775.       i++;
  1776.   *p = '\0';
  1777.   if (i)
  1778.     for (tp = TimezoneTable; tp->name; tp++)
  1779.       if (strcmp (buff, tp->name) == 0)
  1780.     {
  1781.       yylval.Number = tp->value;
  1782.       return tp->type;
  1783.     }
  1784.  
  1785.   return tID;
  1786. }
  1787.  
  1788. static int
  1789. yylex ()
  1790. {
  1791.   register char c;
  1792.   register char *p;
  1793.   char buff[20];
  1794.   int Count;
  1795.   int sign;
  1796.  
  1797.   for (;;)
  1798.     {
  1799.       while (ISSPACE (*yyInput))
  1800.     yyInput++;
  1801.  
  1802.       if (ISDIGIT (c = *yyInput) || c == '-' || c == '+')
  1803.     {
  1804.       if (c == '-' || c == '+')
  1805.         {
  1806.           sign = c == '-' ? -1 : 1;
  1807.           if (!ISDIGIT (*++yyInput))
  1808.         /* skip the '-' sign */
  1809.         continue;
  1810.         }
  1811.       else
  1812.         sign = 0;
  1813.       for (yylval.Number = 0; ISDIGIT (c = *yyInput++);)
  1814.         yylval.Number = 10 * yylval.Number + c - '0';
  1815.       yyInput--;
  1816.       if (sign < 0)
  1817.         yylval.Number = -yylval.Number;
  1818.       return sign ? tSNUMBER : tUNUMBER;
  1819.     }
  1820.       if (ISALPHA (c))
  1821.     {
  1822.       for (p = buff; (c = *yyInput++, ISALPHA (c)) || c == '.';)
  1823.         if (p < &buff[sizeof buff - 1])
  1824.           *p++ = c;
  1825.       *p = '\0';
  1826.       yyInput--;
  1827.       return LookupWord (buff);
  1828.     }
  1829.       if (c != '(')
  1830.     return *yyInput++;
  1831.       Count = 0;
  1832.       do
  1833.     {
  1834.       c = *yyInput++;
  1835.       if (c == '\0')
  1836.         return c;
  1837.       if (c == '(')
  1838.         Count++;
  1839.       else if (c == ')')
  1840.         Count--;
  1841.     }
  1842.       while (Count > 0);
  1843.     }
  1844. }
  1845.  
  1846. #define TM_YEAR_ORIGIN 1900
  1847.  
  1848. /* Yield A - B, measured in seconds.  */
  1849. static long
  1850. difftm (a, b)
  1851.      struct tm *a, *b;
  1852. {
  1853.   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
  1854.   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
  1855.   long days = (
  1856.   /* difference in day of year */
  1857.         a->tm_yday - b->tm_yday
  1858.   /* + intervening leap days */
  1859.         + ((ay >> 2) - (by >> 2))
  1860.         - (ay / 100 - by / 100)
  1861.         + ((ay / 100 >> 2) - (by / 100 >> 2))
  1862.   /* + difference in years * 365 */
  1863.         + (long) (ay - by) * 365
  1864.   );
  1865.   return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
  1866.         + (a->tm_min - b->tm_min))
  1867.       + (a->tm_sec - b->tm_sec));
  1868. }
  1869.  
  1870. time_t
  1871. get_date (p, now)
  1872.      const char *p;
  1873.      const time_t *now;
  1874. {
  1875.   struct tm tm, tm0, *tmp;
  1876.   time_t Start;
  1877.  
  1878.   yyInput = p;
  1879.   Start = now ? *now : time ((time_t *) NULL);
  1880.   tmp = localtime (&Start);
  1881.   yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
  1882.   yyMonth = tmp->tm_mon + 1;
  1883.   yyDay = tmp->tm_mday;
  1884.   yyHour = tmp->tm_hour;
  1885.   yyMinutes = tmp->tm_min;
  1886.   yySeconds = tmp->tm_sec;
  1887.   yyMeridian = MER24;
  1888.   yyRelSeconds = 0;
  1889.   yyRelMinutes = 0;
  1890.   yyRelHour = 0;
  1891.   yyRelDay = 0;
  1892.   yyRelMonth = 0;
  1893.   yyRelYear = 0;
  1894.   yyHaveDate = 0;
  1895.   yyHaveDay = 0;
  1896.   yyHaveRel = 0;
  1897.   yyHaveTime = 0;
  1898.   yyHaveZone = 0;
  1899.  
  1900.   if (yyparse ()
  1901.       || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1902.     return -1;
  1903.  
  1904.   tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN + yyRelYear;
  1905.   tm.tm_mon = yyMonth - 1 + yyRelMonth;
  1906.   tm.tm_mday = yyDay + yyRelDay;
  1907.   if (yyHaveTime || (yyHaveRel && !yyHaveDate && !yyHaveDay))
  1908.     {
  1909.       tm.tm_hour = ToHour (yyHour, yyMeridian);
  1910.       if (tm.tm_hour < 0)
  1911.     return -1;
  1912.       tm.tm_min = yyMinutes;
  1913.       tm.tm_sec = yySeconds;
  1914.     }
  1915.   else
  1916.     {
  1917.       tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
  1918.     }
  1919.   tm.tm_hour += yyRelHour;
  1920.   tm.tm_min += yyRelMinutes;
  1921.   tm.tm_sec += yyRelSeconds;
  1922.   tm.tm_isdst = -1;
  1923.   tm0 = tm;
  1924.  
  1925.   Start = mktime (&tm);
  1926.  
  1927.   if (Start == (time_t) -1)
  1928.     {
  1929.  
  1930.       /* Guard against falsely reporting errors near the time_t boundaries
  1931.          when parsing times in other time zones.  For example, if the min
  1932.          time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
  1933.          of UTC, then the min localtime value is 1970-01-01 08:00:00; if
  1934.          we apply mktime to 1970-01-01 00:00:00 we will get an error, so
  1935.          we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
  1936.          zone by 24 hours to compensate.  This algorithm assumes that
  1937.          there is no DST transition within a day of the time_t boundaries.  */
  1938.       if (yyHaveZone)
  1939.     {
  1940.       tm = tm0;
  1941.       if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
  1942.         {
  1943.           tm.tm_mday++;
  1944.           yyTimezone -= 24 * 60;
  1945.         }
  1946.       else
  1947.         {
  1948.           tm.tm_mday--;
  1949.           yyTimezone += 24 * 60;
  1950.         }
  1951.       Start = mktime (&tm);
  1952.     }
  1953.  
  1954.       if (Start == (time_t) -1)
  1955.     return Start;
  1956.     }
  1957.  
  1958.   if (yyHaveDay && !yyHaveDate)
  1959.     {
  1960.       tm.tm_mday += ((yyDayNumber - tm.tm_wday + 7) % 7
  1961.              + 7 * (yyDayOrdinal - (0 < yyDayOrdinal)));
  1962.       Start = mktime (&tm);
  1963.       if (Start == (time_t) -1)
  1964.     return Start;
  1965.     }
  1966.  
  1967.   if (yyHaveZone)
  1968.     {
  1969.       long delta = yyTimezone * 60L + difftm (&tm, gmtime (&Start));
  1970.       if ((Start + delta < Start) != (delta < 0))
  1971.     return -1;        /* time_t overflow */
  1972.       Start += delta;
  1973.     }
  1974.  
  1975.   return Start;
  1976. }
  1977.  
  1978. #if    defined (TEST)
  1979.  
  1980. /* ARGSUSED */
  1981. int
  1982. main (ac, av)
  1983.      int ac;
  1984.      char *av[];
  1985. {
  1986.   char buff[MAX_BUFF_LEN + 1];
  1987.   time_t d;
  1988.  
  1989.   (void) printf ("Enter date, or blank line to exit.\n\t> ");
  1990.   (void) fflush (stdout);
  1991.  
  1992.   buff[MAX_BUFF_LEN] = 0;
  1993.   while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
  1994.     {
  1995.       d = get_date (buff, (time_t *) NULL);
  1996.       if (d == -1)
  1997.     (void) printf ("Bad format - couldn't convert.\n");
  1998.       else
  1999.     (void) printf ("%s", ctime (&d));
  2000.       (void) printf ("\t> ");
  2001.       (void) fflush (stdout);
  2002.     }
  2003.   exit (0);
  2004.   /* NOTREACHED */
  2005. }
  2006. #endif /* defined (TEST) */
  2007.